package com.ruoyi.web.controller;

import com.ruoyi.system.domain.dto.Train_ResultDTO;
import com.ruoyi.system.service.trainingDataUploadService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Ly lilongfei
 * @date 2024/11/5
 * @Description
 */
@RestController
@RequestMapping("/api/training-data-upload")
public class TrainResultUploadController {

    @Resource
    private trainingDataUploadService trainingDataService;

    @PostMapping("/batch")
    public ResponseEntity<String> uploadBatchTrainingData(@RequestBody List<Train_ResultDTO> trainingDataList) {
        try {
            trainingDataService.saveAll(trainingDataList);
            return ResponseEntity.ok("批量训练数据上传成功");
        } catch (Exception e) {
            return ResponseEntity.badRequest().body("批量上传失败: " + e.getMessage());
        }
    }
    @PostMapping("/single")
    public ResponseEntity<String> uploadSingleTrainingData(@RequestBody Train_ResultDTO trainingData) {
        try {
            trainingDataService.save(trainingData);
            return ResponseEntity.ok("训练数据上传成功");
        } catch (Exception e) {
            return ResponseEntity.badRequest().body("批量上传失败: " + e.getMessage());
        }
    }
}
